package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.dto.DataDto;
import com.ruoyi.system.domain.dto.RiverDetailDto;
import com.ruoyi.system.domain.dto.RiverListDto;
import com.ruoyi.system.service.OneMapFwService;
import com.ruoyi.system.service.SmallToolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author QiuYuchun
 * Date: 2023/12/18
 * Time: 15:52
 */

@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private OneMapFwService oneMapFwService;
    @Autowired
    private SmallToolService smallToolService;

    @PostMapping("/riverList/river")
    public R<String> getRiverList(@RequestBody RiverListDto riverListDto) {
        //名录 流域 河流

        String ans = oneMapFwService.getRiverList(riverListDto);

        if (ans == null) {
            return R.fail("err!");
        } else {
            return R.ok(ans);
        }
    }

    @PostMapping("/riverDetails/getElementDetailNoEncrypt")
    public R<String> getRiverDetails(@RequestBody RiverDetailDto riverDetailDto) {
        //名录 流域 河流

        String ans = oneMapFwService.getRiverDetail(riverDetailDto);

        if (ans == null) {
            return R.fail("err!");
        } else {
            return R.ok(ans);
        }
    }

//   @GetMapping("/holiday/single")
//    public R<String> getCalendar(@RequestParam("dataTime") String dataTime)
    @PostMapping("/holiday/single")
    public R<String> getCalendar(@RequestBody DataDto dataDto) {
        String ans = smallToolService.getCalendar(dataDto.getDateTime());
        if (ans == null) {
            return R.fail("err!");
        } else {
            return R.ok(ans);
        }
    }

    //    @GetMapping("/weather/current")
//    public R<String> getWeather(@RequestParam("cityName") String cityName) {
    @PostMapping("/weather/current")
    public R<String> getWeather(@RequestBody DataDto dataDto) {
        String ans = smallToolService.getWeather(dataDto.getCityName());
        if (ans == null) {
            return R.fail("err!");
        } else {
            return R.ok(ans);
        }
    }

//    @GetMapping("/weather/forecast")
//    public R<String> getRecentWeather(@RequestParam("cityName") String cityName) {
    @PostMapping("/weather/forecast")
    public R<String> getRecentWeather(@RequestBody DataDto dataDto) {
        String ans = smallToolService.getRecentWeather(dataDto.getCityName());
        if (ans == null) {
            return R.fail("err!");
        } else {
            System.out.println("ans"+ans);
            return R.ok(ans);
        }
    }

    @PostMapping("/jokes/list")
    public R<String> getJokes() {
        String ans = smallToolService.getJokes();
        if (ans == null) {
            return R.fail("err!");
        } else {
            System.out.println("ans"+ans);
            return R.ok(ans);
        }
    }
}
